#This code produces Table 16 in Appendix H
if(!dir.exists("tabs")){dir.create("tabs")}
if(!dir.exists("tabs/appendix")){dir.create("tabs/appendix")}


rm(list = ls())
library(lubridate)
library(foreign)
library(ggthemes)
library(stats)
library(lmtest)
library(sandwich)
library(quanteda)
library(stm)
library(stats)
library(ggpubr)
library(tidyverse)
library(tidytext)


# tishreen ----------------------------------------------------------------
tishreen = read.csv("tishreen.csv")
tishreen = tishreen %>% 
  as_tibble() %>% 
  mutate(date = ymd(date),
         week = floor_date(date, unit = "week"),
         isr_pct = ofhlisrael/totalofhl) %>% 
  group_by(week) %>% 
  mutate(isr_avg = sum(ofhlisrael)/sum(totalofhl))

#Generate missing data
df = tibble(date = seq(ymd("1987-01-03"), ymd("2002-12-31"), by = "1 day"))
tishreen = left_join(df, tishreen, "date")

# weekdays tishreen ----------------------------------------------------------------
library(estimatr)
library(texreg)

mod1 = lm_robust(ofhlisrael ~ ofpicturesofbasharorhafez, data = tishreen)
mod2 = lm_robust(ofhlisrael ~ ofpicturesofbasharorhafez + as.factor(floor_date(date, "year")), data = tishreen)

texreg(list(mod1, mod2), omit.coef = "factor", custom.coef.names = c("Intercept", "Assad Pictures"),
       caption = "Relationship between coverage of Israel and pictures of Assad on \\textit{Tishreen} front page", 
       label = "tab:assad_pics", include.ci = F, include.rsquared = F, include.adjrs = F, 
       include.nobs = F, reorder.coef = c(2, 1), include.rmse = F,
       float.pos = "H", custom.gof.rows = list("Year FE" = c("No", "Yes")), file = "tabs/appendix/assad_pics")
